home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™94 / Talks & Papers / Michael D. Crawford↵ / Word Services SDK 1.0.5 / Writeswell Jr. Source / InitMenu.c < prev    next >
Text File  |  1992-10-23  |  4KB  |  168 lines

  1. /* InitMenu.c
  2.  * ©1992 Working Software, Inc.
  3.  * This source code is copyrighted.  Permission is granted to use the Word Services
  4.  * portion of the Writeswell Jr. source code in your own programs, but you 
  5.  * may not distribute the Writeswell Jr. word-processor code as a 
  6.  * commercial product.  If you modify the code, please do not call it 
  7.  * Writeswell Jr. (or Writeswell.)  This will ensure that people understand the 
  8.  * program and don’t have to deal with a number of different versions with 
  9.  * who-knows-what going on in the code.
  10.  * 
  11.  * Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
  12.  */
  13.  
  14. #include <EPPC.h>
  15. #include <AppleEvents.h>
  16. #include "TBConstants.h"
  17. #include "Prefs.h"
  18. #include "InitMenu.h"
  19. #include "Gripe.h"
  20. #include "FontMenu.h"
  21. #include "TBGlobals.h"
  22.  
  23. void SetServiceIcon( short item, short serviceNumber, MenuHandle servMenu );
  24.  
  25. void PutUpMenus( void )
  26. {
  27.     Handle        myMenuBar;
  28.     MenuHandle    appleMenu;
  29.     MenuHandle    fontMenu;
  30.     
  31.     InitMenus();
  32.     
  33.     myMenuBar = GetNewMBar( kMBarID );
  34.     if ( !myMenuBar ){
  35.         Gripe( "\pCannot get menu bar" );
  36.         return;
  37.     }
  38.  
  39.     appleMenu = (MenuHandle)GetResource( 'MENU', kAppleMenuID );
  40.     if ( !appleMenu ){
  41.         Gripe( "\pcannot get Apple Menu Handle" );
  42.         return;
  43.     }
  44.     AddResMenu( appleMenu, 'DRVR' );
  45.  
  46.     fontMenu = (MenuHandle)GetResource( 'MENU', kFontMenuID );
  47.     if ( !fontMenu ){
  48.         Gripe( "\pcannot get Font Menu Handle" );
  49.         return;
  50.     }
  51.     AddResMenu( fontMenu, 'FONT' );
  52.  
  53.     InitStyleMenu();
  54.  
  55.     SetMenuBar( myMenuBar );
  56.     DrawMenuBar();
  57.         
  58.     return;
  59. }
  60.  
  61. void PutUpSys6Menus( void )
  62. {
  63.     MenuHandle        servMenu;
  64.  
  65.     PutUpMenus();
  66.  
  67.     servMenu = GetServiceMenu();
  68.     if ( !servMenu ){
  69.         Gripe( "\pCannot get service menu handle" );
  70.         return;
  71.     }
  72.  
  73.     DisableItem( servMenu, 0 );            /* Disable the whole menu */
  74.     DrawMenuBar();
  75.     
  76.     return;
  77. }
  78.  
  79. void PutUpSys7Menus( void )
  80. {
  81.     PutUpMenus();
  82.     BuildServiceMenu();
  83. }
  84.  
  85. OSErr BuildServiceMenu( void )
  86. {
  87.     WWJrPrefsHdl    prefHdl;
  88.     short            i;
  89.     short            servNum;
  90.     StringHandle    menuStrHdl;
  91.     short            curFile;
  92.     MenuHandle        servMenu;
  93.     short            resID;
  94.  
  95.     prefHdl = GetPrefHandle();
  96.     if ( !prefHdl ){
  97.         Gripe( "\pCannot get preferences handle" );
  98.         return;
  99.     }
  100.  
  101. #ifdef NEVER                        /* This will return in a future version */
  102.     CheckSelectMenu( prefHdl );
  103. #endif
  104.     
  105.     servMenu = GetServiceMenu();
  106.     if ( !servMenu ){
  107.         Gripe( "\pCannot get service menu handle" );
  108.         return;
  109.     }
  110.  
  111.     curFile = CurResFile();
  112.     UseResFile( gPrefFileRefNum );
  113.  
  114.  
  115.     /* This routine here could be modified to sort the service menu into some
  116.      * order, such as alphabetical, by associating the item numbers with the
  117.      * resource numbers in the desired order.
  118.      */
  119.  
  120.     servNum = 0;
  121.  
  122.     for ( i = 0; i < kMaxServices; i++ ){
  123.         if ( (*prefHdl)->serviceType[ i ] != kNoService ){
  124.         
  125.             resID = kServiceBaseID + i;
  126.  
  127.             menuStrHdl = GetString( resID );
  128.             if ( !menuStrHdl ){
  129.                 Gripe( "\pCannot get string resource for service menu" );
  130.                 UseResFile( curFile );
  131.                 return resNotFound;
  132.             }
  133.             HLock( menuStrHdl );
  134.             AppendMenu( servMenu, *menuStrHdl );    /* Note: this will interpret special chars */
  135.             HUnlock( menuStrHdl );
  136.             ReleaseResource( menuStrHdl );
  137.             
  138.             SetServiceIcon( servNum + kSMDash + 1, i, servMenu );
  139.             
  140.             gServItemID[ servNum++ ] = resID;
  141.             
  142.         }
  143.     }
  144.  
  145.     UseResFile( curFile );
  146.     return noErr;
  147. }
  148.  
  149. void SetServiceIcon( short item, short serviceNumber, MenuHandle servMenu )
  150. {
  151.     Handle    sicnHandle;
  152.     short    resID;
  153.  
  154.     resID = kMenuIconBaseID + serviceNumber;
  155.     
  156.     sicnHandle = GetResource( 'SICN', resID );
  157.     
  158.     if ( !sicnHandle ){
  159.         return;
  160.     }
  161.     
  162.     /* ReleaseResource( sicnHandle ); */
  163.     
  164.     SetItemCmd( servMenu, item, (short) 0x01e );
  165.     SetItemIcon( servMenu, item, (unsigned char)(serviceNumber + 1) );
  166.  
  167.     return;
  168. }